from sqlalchemy import Column, BigInteger, String, SmallInteger, Date, Text, DateTime, Index
from app.config.database import Base
from datetime import datetime, date
from pydantic import BaseModel, ConfigDict
from typing import Optional

class Teacher(Base):
    __tablename__ = "edu_teacher"
    
    id = Column(BigInteger, primary_key=True, autoincrement=True, comment="教师ID")
    user_id = Column(BigInteger, nullable=False, comment="用户ID")
    teacher_no = Column(String(20), nullable=False, unique=True, comment="工号")
    teacher_name = Column(String(50), nullable=False, comment="教师姓名")
    gender = Column(SmallInteger, nullable=False, comment="性别：1-男 2-女")
    birth_date = Column(Date, comment="出生日期")
    id_card = Column(String(20), comment="身份证号")
    phone = Column(String(20), comment="联系电话")
    email = Column(String(100), comment="邮箱")
    subject_code = Column(String(20), comment="任教科目编码")
    job_title = Column(String(50), comment="职称")
    status = Column(SmallInteger, nullable=False, default=1, comment="状态：0-离职 1-在职")
    create_time = Column(DateTime, default=datetime.utcnow, nullable=False, comment="创建时间")
    update_time = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False, comment="更新时间")
    
    # 索引
    __table_args__ = (
        Index('uk_teacher_no', 'teacher_no'),
        Index('idx_teacher_name', 'teacher_name')
    )

class TeacherInDB(BaseModel):
    id: int
    user_id: int
    teacher_no: str
    teacher_name: str
    gender: int
    birth_date: Optional[date] = None
    id_card: Optional[str] = None
    phone: Optional[str] = None
    email: Optional[str] = None
    subject_code: Optional[str] = None
    job_title: Optional[str] = None
    status: int = 1
    create_time: Optional[datetime] = None
    update_time: Optional[datetime] = None

    model_config = ConfigDict(from_attributes=True)